// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
let base = require("panelBase");
let viewConfig = {
    btn_back:{
        node:null,
        name:"btn_back",
        eventType:"click",
        cb:"onBtnBackClick",
    },
    btn_tx:{
        node:null,
        name:"tog/btn_tx",
        eventType:"toggle",
        cb:"onBtnTxClick",
    },
    btn_coin:{
        node:null,
        name:"tog/btn_coin",
        eventType:"toggle",
        cb:"onBtnCoinClick",
    },
    tx_sc:{
        node:null,
        name:'tx_sc',
    },
    tx_txt:{
        node:null,
        name:"tog/btn_tx/con",
    },
    coin_txt:{
        node:null,
        name:"tog/btn_coin/con"
    },
    tx_item:{
        node:null,
        name:"tx_item",
        active:false,
    },
    coin_item:{
        node:null,
        name:"coin_item",
        active:false,
    }

}
cc.Class({
    extends: base,

    properties: {
        mySc:null,
        red:null,
        black:null,
        curIndex:-1,
    },

    init(){
        this._super(viewConfig);
        this.isInited = true;
        this.red = new  cc.Color(255,143,102,255);
        this.black = new cc.Color(51,51,51,255);
        this.node.addComponent("myScrollView");
        this.mySc = this.node.getComponent("myScrollView")
        this.mySc.init(viewConfig["tx_sc"].node);
        this.onHide();
    },

    onShow(){
        this._super();
        viewConfig["btn_tx"].node.getComponent(cc.Toggle).isChecked = true;
        viewConfig["btn_coin"].node.getComponent(cc.Toggle).isChecked = false;
        //测试
       

    //   setTimeout(()=>{
    //     let txList = [];
    //     let coinList = [];
    //     for(let i = 0 ; i < 10 ;++i)
    //     {   
    //         let txData = {
    //             info:"余额提现到微信红包",
    //             status:i%2 == 0 ? 0:-1,
    //             time:"01月20 18:20",
    //             money:0.5,
    //         }
    //         let coinData = {
    //             cakeName:"草坪金币",
    //             time:"01月20日 18:20",
    //             money:0.1,
    //         }

    //         txList.push(txData);
    //         coinList.push(coinData);
    //     }
    //     this.mySc.showData(viewConfig["tx_item"].node,txList,this.initTxItem.bind(this),10,0)
    //     this.mySc.showData(viewConfig["coin_item"].node,coinList,this.initCoinItem.bind(this),10,1)
    //     //默认显示提现记录
    //     this.onBtnTxClick(0)
    
    //   },1000);

    },

    initTxItem(node,data){
        if(!node || !data )
            return ;
        this.updateInfo(node.getChildByName("info"),data["info"],cc.Label);
        this.updateInfo(node.getChildByName("time"),data["time"],cc.Label);
        this.updateInfo(node.getChildByName("coinNum"),data["money"],cc.Label);
        let statusLabel = node.getChildByName("status")
        let ret = ""
        if(data["status"] == 0)
        {
            statusLabel.color = new cc.Color(0,160,233,255)
            ret = "已到账"
        }
        else
        {
            statusLabel.color = new  cc.Color(255,0,0,255);
            ret = "未到账"
        }
        this.updateInfo(statusLabel,ret,cc.Label);
    },
    initCoinItem(node,data){
        if(!node || !data )
            return ;
          this.updateInfo(node.getChildByName("cakeName"),data["cakeName"],cc.Label)
          this.updateInfo(node.getChildByName("time"),data["time"],cc.Label);
          this.updateInfo(node.getChildByName("coinNum"),data["money"],cc.Label);  
    },
    onBtnBackClick(){
        this.onHide();
    },
    // 点击提现明细
    onBtnTxClick(){
        this.onShowData()
        let tx_txt = viewConfig["tx_txt"].node;
        let coin_txt = viewConfig["coin_txt"].node;
        tx_txt.color = this.red;
        coin_txt.color = this.black;
    },
    // 点击金币明细
    onBtnCoinClick(){
        this.onShowData(1);
        let tx_txt = viewConfig["tx_txt"].node;
        let coin_txt = viewConfig["coin_txt"].node;
        tx_txt.color = this.black;
        coin_txt.color = this.red;
    },

    onShowData(index = 0){
        if(this.curIndex == index)
            return ;
        this.mySc.showDataByGid(index);
        this.curIndex = index;
    },
    onHide(){
        this._super();
        this.onShowData(-1);
    },

    onDestroy(){
        for(let key in viewConfig)
        {
            viewConfig[key].node = null;
        }
    },
});
